<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="layout :: htmlhead" th:with="title='后台管理'">
</head>
<body>
	<div class="layui-layout layui-layout-admin">
    <!--头-->
    <div th:replace="fragments/head :: header"></div>
        <div class="layui-body" style="margin-left: 50px;margin-right: 50px;">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px; width:80%">
            <legend>编辑${comment}</legend>
        </fieldset>

    <div class="layui-btn-group">
    	<button class="layui-btn" onclick="backList()">返回列表</button>
    </div>
        <form class="layui-form" action="/${javaBeanName}/update" target="rfFrame" lay-filter="example" style="margin-top: 20px;">
            
    <#list columns as col>
	    <#if (!col.primaryKey) && (col.comment!='')>
	    	<#switch col.javaType>
	    	<#case "Date">
	    		<div class="layui-form-item">
	                <label class="layui-form-label" style="width:10%">${col.comment}:</label>
	                <div class="layui-input-inline" style="width:50%">
	                    <input type="text" name="${col.columnJavaName}" lay-verify="${col.columnJavaName}" autocomplete="off" placeholder="请输入${col.comment}" class="layui-input advanceDate"/>
	                </div>
	            </div>
	    		<#break>
	    	<#case "Double">
	    	<#case "Integer">
	    	<#case "Float">
	    	<#case "BigInteger">
	    		<div class="layui-form-item">
	                <label class="layui-form-label" style="width:10%">${col.comment}:</label>
	                <div class="layui-input-inline" style="width:50%">
	                    <input type="text" name="${col.columnJavaName}" lay-verify="${col.columnJavaName}|number"  maxlength="${col.length}" autocomplete="off" placeholder="请输入${col.comment}" class="layui-input"/>
	                </div>
	            </div>
	    		<#break>
	    	<#default>
	            <div class="layui-form-item">
	                <label class="layui-form-label" style="width:10%">${col.comment}:</label>
	                <div class="layui-input-inline" style="width:50%">
	                    <input type="text" name="${col.columnJavaName}" lay-verify="${col.columnJavaName}" maxlength="${col.length/3?ceiling}" autocomplete="off" placeholder="请输入${col.comment}" class="layui-input"/>
	                </div>
	            </div>
	    	</#switch>
        <#else>
            <div class="layui-form-item" style="display:none">
                <label class="layui-form-label" style="width:10%">${col.comment}:</label>
                <div class="layui-input-inline" style="width:50%">
                    <input type="text" name="${col.columnJavaName}" lay-verify="${col.columnJavaName}" autocomplete="off" placeholder="请输入${col.comment}" class="layui-input"/>
                </div>
            </div>
	    </#if>
    </#list>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="updatecommit">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
        <iframe id="rfFrame" name="rfFrame" src="about:blank" style="display:none;"></iframe>
        <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
        <script type='text/javascript'>
            layui.use(['form','laydate'], function(){
                var $ = layui.jquery;
                var form = layui.form;
				  var laydate = layui.laydate;
                form.render();
			  //常规用法
			  lay('.advanceDate').each(function(){
				laydate.render({
					elem: this
				});
				});
			
			  //常规用法
			  lay('.advanceTime').each(function(){
				laydate.render({
					elem: this,
					type: 'datetime'
				});
				});
				getUrlParam = function (name) {
				   var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				   var r = window.location.search.substr(1).match(reg);
				   if (r != null) return unescape(r[2]); return null;
				}
				var id = getUrlParam('id');
				console.info ('id:'+id);
				if (id != '' && id != null){
				    $.get("detail",{id:id},function(data){
				    	console.info(data);  
				    	form.val('example', data);
				    });
				}
				
				//自定义表单验证规则举例 
				form
					.verify({
						ccode : function(value) {
							if (value.length < 5) {
								return 'ccode至少得5个字符啊';
							}
						},
						email : [
								/^[a-z0-9._%-]+@([a-z0-9-]+\.)+[a-z]{2,4}$|^1[3|4|5|7|8]\d{9}$/,
								'邮箱格式不对' ]
				});
				  //监听提交
				form.on('submit(updatecommit)', 
					function(data){
					  console.info(data);
				      layer.msg('修改成功'+data);
				      window.location="listPage";
					}
				);
            });
		function backList(){
			  window.location='listPage.html';
		}
        </script>
        </div>
        <!--底部-->
        <div th:replace="fragments/footer :: footer"></div>
        </div>
</body>
</html>